package com.example.stukotlin.extendAndTypeid

/**
 * 运算符重载 operator
 */
fun main() {
    val money1=Money(27)
    val money2 = Money(18)
    val money = money1 + money2
    println(money.value)
}


class Money(val value: Int) {
    /**
     * 运算符重载
     * 接收参数和返回值自己定义
     */
    operator fun plus(money: Money): Money {
        val sum = value + money.value
        return Money(sum)
    }

    /**
     * 运算符多重重载
     */
    operator fun plus(newValue: Int): Money {
        val sum = value + newValue
        return Money((sum))
    }
}
